package com.example.smartcity.ui.Adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.smartcity.R;
import com.example.smartcity.ui.Bean.ManagerCarBean;
import com.google.android.material.textfield.TextInputEditText;

import java.util.ArrayList;

public class ManagerCarAdapter extends RecyclerView.Adapter<ManagerCarAdapter.MyViewHolder> {

    int Resource;
    private ArrayList<ManagerCarBean> list;
    public ManagerCarAdapter(int Resource,ArrayList<ManagerCarBean> list){
        this.list=list;
        this.Resource = Resource;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(Resource,parent,false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        holder.CarMessage1.setText(list.get(position).getCarMessage1());
        holder.CarMessage2.setText(list.get(position).getCarMessage2());
        holder.CarMessage3.setText(list.get(position).getCarMessage3());
        holder.CarMessage4.setText(list.get(position).getCarMessage4());
        holder.CarMessage5.setText(list.get(position).getCarMessage5());
        holder.CarMessage6.setText(list.get(position).getCarMessage6());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

     class MyViewHolder extends RecyclerView.ViewHolder{
        private TextInputEditText CarMessage1;
        private TextInputEditText CarMessage2;
        private TextInputEditText CarMessage3;
        private TextInputEditText CarMessage4;
        private TextInputEditText CarMessage5;
        private TextInputEditText CarMessage6;
        public TextView TV_submit;
        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            CarMessage1 = itemView.findViewById(R.id.CarMessage1);
            CarMessage2 = itemView.findViewById(R.id.CarMessage2);
            CarMessage3 = itemView.findViewById(R.id.CarMessage3);
            CarMessage4 = itemView.findViewById(R.id.CarMessage4);
            CarMessage5 = itemView.findViewById(R.id.CarMessage5);
            CarMessage6 = itemView.findViewById(R.id.CarMessage6);
            TV_submit = itemView.findViewById(R.id.TV_submit);
            TV_submit.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    listener.OnItemClickListener(getAdapterPosition(),itemView);
                }
            });
        }
    }

    public OnItemClickListener listener;
    public void SetOnItemClickListener(OnItemClickListener listener){
        this.listener = listener;
    }
    public interface OnItemClickListener{
        void OnItemClickListener(int position,View itemView);
    }
}
